/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package rule;

import java.util.HashSet;

/**
 *
 * @author Daniel Gribel
 */
public class AlphaNumericAndSpecialChar extends Rule {

    public AlphaNumericAndSpecialChar() {
        super("2 combo points for (letters or numbers) and special chars");
    }

    @Override
    public void checkConditions(String dataEntry) {
        boolean lower = false;
        boolean upper = false;
        int cont = 0;
        int contSimbs = 0;
        
        HashSet<Character> simbols = getSpecialChars();
        
        for (int i = 0; i < dataEntry.length(); i++) {
            if (Character.isLowerCase(dataEntry.charAt(i)))
                lower = true;
            
            if (Character.isUpperCase(dataEntry.charAt(i)))
                upper = true;
            
            if (Character.isDigit(dataEntry.charAt(i)))
                cont++;
            
            if(simbols.contains(dataEntry.charAt(i)))
                contSimbs++;
        }
        
        if ((cont > 0 || lower || upper) && contSimbs > 0)
            setScore(2);
    }

    private HashSet<Character> getSpecialChars() {
        HashSet<Character> simbols = new HashSet<Character>();
        simbols.add('!');
        simbols.add('@');
        simbols.add('#');
        simbols.add('$');
        simbols.add('%');
        simbols.add('^');
        simbols.add('&');
        simbols.add('*');
        simbols.add('?');
        simbols.add('_');
        simbols.add('~');
        return simbols;
    }

    @Override
    public String outputMessage() {
        return getLog();
    }
    
}
